package com.new_blog.config;

import com.new_blog.common.AppVarible;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-01-25
 * Time:13:33
 * Text：拦截器
 */
public class LoginIntercept implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession(false);
        if (session != null && session.getAttribute(AppVarible.SESSION_USERINFO_KEY) != null) {
            //用户已经登陆
            return true;
        }
        response.sendRedirect("/login.html");
        return false;
    }
}
